<script setup lang="ts">
import { ref } from 'vue'
import { channels } from '@/api/index'
import type { TchannelsItem } from '@/types/index'

const props = defineProps<{
  currId: number
}>()
const emits = defineEmits<{
  (e: 'setCurrId', id: number): void
}>()

const list = ref<TchannelsItem>([])
const getData = async () => {
  const res = await channels()
  list.value = res.data.data.channels
  emits('setCurrId', list.value[0].id)
}
getData()
</script>

<template>
  <div class="channel-nav">
    <nav class="list">
      <a
        class="item"
        :class="{ active: item.id === currId }"
        href="javascript:;"
        v-for="item in list"
        :key="item.id"
        @click="emits('setCurrId', item.id)"
      >
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>
